<%@page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Air Transport - Main Page</title>
</head>
<body>

<c:if test="${not user.accessed}">
<c:redirect url="index.html"></c:redirect>
</c:if>

<c:if test="${not user.loggedIn}">
<c:redirect url="index.html"></c:redirect>
</c:if>


<h2><u>Air Transport Service - Main Page</u></h2>

<jsp:include page="header.jsp"></jsp:include>
<c:choose>
	<c:when test="${not empty flights}">
		Flights: <br>
		<table border="1">
			<tr bgcolor="lightgrey">
				<th>No</th>
				<th>Flight ID</th>
				<th>Deparutre Time</th>
				<th>Arrival Time</th>
				<th>Source</th>
				<th>Destination</th>
				<th>Reserved Seats</th>
				<th>Reservation</th>
			</tr>
			<c:forEach items="${flights}" var="flight" varStatus="status">

				<c:choose>
					<c:when test="${(status.index)%2 eq 0}">
						<tr bgcolor=<%= "#99CCFF" %>>
					</c:when>
					<c:otherwise>
						<tr bgcolor=<%= "#CCCCCC" %>>
					</c:otherwise>
				</c:choose>
				<td align="center">${status.index + 1}.</td>
				<td align="center"><a href='flight.html?flightid=${flight.id}'>${flight.id}</a></td>
				<td align="center">${flight.departureTimeFormated}</td>
				<td align="center">${flight.arrivalTimeFormated}</td>
				<td align="center">${flight.source}</td>
				<td align="center">${flight.destination}</td>
				<td align="center">${flight.reservedSeatsCount}</td>

				<c:choose>
					<c:when test="${not flight.expired}">
						<form method="get" action="reservation.html">
						<td align="center"><input type="hidden" name="flightid"
							value=${flight.id}> <input type="submit" value="Reserve"></td>
						</form>
					</c:when>
					<c:otherwise>
						<td align="center">Expired</td>
					</c:otherwise>
				</c:choose>
				</tr>			
			</c:forEach>
		</table>
	</c:when>
	<c:otherwise>
		Ne postoji nijedan let!<br />
	</c:otherwise>
</c:choose>

<hr />
<p><a href="newflight.html">Add New Flight</a></p>
<p><a href="newcity.html">Add New City</a></p>
<p><a href="logout.html">Logout</a></p>


<jsp:include page="footer.jsp"></jsp:include>

</body>
</html>